package com.monise.util;

import java.util.List;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.view.JasperViewer;

import com.monise.model.ApontamentoHora;

public class GerarRelatorio {
	
	public void gerarRelatorioHorasTrabalhadas(List<ApontamentoHora> apontamentos, String nome){
		try {
			JasperReport report = JasperCompileManager .compileReport("src/com/monise/relatorio/relatorio.jrxml");
			
			 /*  Map<String, Object> parameters = new HashMap<String, Object>();  
		       parameters.put("data",apontamentos.get(0).getData().toString());   
		       parameters.put("horaAlmocoS",apontamentos.get(0).getHoraAlmocoS());   
		       parameters.put("horaAlmocoV",apontamentos.get(0).getHoraAlmocoV());   
		       parameters.put("horaEntrada",apontamentos.get(0).getHoraEntrada());   
		       parameters.put("horaSaida",apontamentos.get(0).getHoraSaida());   
		       parameters.put("funcionario.nome",apontamentos.get(0).getFuncionario().getNome()); 
		       parameters.put("observacao",apontamentos.get(0).getObservacao()); */
			
			JasperPrint print = JasperFillManager.fillReport(report, null, new JRBeanCollectionDataSource(apontamentos)); 
			JasperExportManager.exportReportToPdfFile(print, "src/com/monise/relatorio/" + nome); 
			JasperViewer.viewReport(print,false); 
			
		} catch (JRException e) {
			e.printStackTrace();
		} 
    }

}
